<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javascript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

var tempX = 0;
var tempY = 0;

function materia(event){
    //alert("ok");
    document.getElementById('hid').style.display = "none";
    var uid = document.forms[0].uid.value;
    var mat = document.forms[0].mat.value;
    var url = "<?php print $_SESSION['__config__']['root_site'] ?>admin/adm_users/materia.php";
    //var data = "uid="+uid+"&mat="+mat;
    //alert(data);
    //httpRequest("POST", url, true, modMateria, data);
    var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: {uid: uid, mat: mat},
			    	onSuccess: function(transport){
			      		var response = transport.responseText || "no response text";
			      		if(response == "ko"){
			      			alert("I dati inseriti sono errati");
			                return;
			     		}
			     		else{
			     			var dati = response.split(";");
			                var usr = dati[1];
			                var mat = dati[2];
			                var x = document.getElementById(usr);
			                x.innerHTML = "";
			                x.innerHTML = dati[2];
			     		}
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore...") }
			  });
}

function ruolo(_uid){
    var uid = _uid;
    var url = "<?php print $_SESSION['__config__']['root_site'] ?>admin/adm_users/ruolo.php";
    var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: {uid: uid},
			    	onSuccess: function(transport){
			      		var response = transport.responseText || "no response text";
			      		if(response == "ko"){
			      			alert("I dati inseriti sono errati");
			                return;
			     		}
			     		else{
			     			var dati = response.split(";");
			     			var val = dati[0];
			                var usr = dati[1];
			                //alert(dati[1]);
			                var x = document.getElementById(usr);
			                x.innerHTML = "";
			                x.innerHTML =  val;
			     		}
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}

function visualizza(e) {
    var hid = document.getElementById("hid");
    //alert(hid.style.top);
    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }  
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}  
    hid.style.top = parseInt(tempY)+"px";
    //alert(hid.style.top);
    hid.style.left = parseInt(tempX)+"px";
    hid.style.display = "inline";
    return true;
}

</script>
</head>
<body>
    <!--
    DIV nascosto che contiene le materie: ogni riga e' un link che carica materie.php
    -->
    <div id="hid" style="position: absolute; width: 300px; height: 370px; display: none; border: 1px solid; background-color: rgb(245,245,245); padding-left: 10px">
    <?php
    $k = 0;
    while($mt = $res_m->fetch_assoc()){
    ?>
        <a style="<?php if($k%2) print('background-color: #E7E7E7') ?>" href="#" onclick="document.forms[0].mat.value = <?php print $mt['id_materia'] ?>; materia(event); "><?php print $mt['materia'] ?></a><br />
    <?php
        $k++;
    }
    ?>
    </div>
    <div id="header">
		<div class="wrap" style="text-align: center">
			<?php include "../header.php" ?>
		</div>
	</div>
	<div class="wrap">
	<div id="main" style="background-color: #FFFFFF; padding-bottom: 30px; width: 100%">
		<form method="post">
        <table class="admin_table">
            <tr class="admin_title_row">
                <td colspan="3">Elenco Docenti: pagina <?php print $page ?> di <?php print $pagine ?></td>
            </tr>
            <tr class="admin_row">
                <td style="width: 40%" class="adm_titolo_elenco">Nome e cognome</td>
                <td style="width: 40%" class="adm_titolo_elenco">Materia</td>
                <td style="width: 20%" class="adm_titolo_elenco _center">Ruolo</td>
            </tr>
            <tr class="admin_row">
                <td colspan="3"></td>
            </tr>
            <?php
            $x = 1;
            if($res_user->num_rows > $limit)
                $max = $limit;
            else
                $max = $res_user->num_rows;

            while($user = $res_user->fetch_assoc()){
                $ruolo = "SI";
                if($user['ruolo'] != "S")
                    $ruolo = "NO";
                if($x > $limit) break;
            ?>
            <tr>
                <td class="admin_row<?php if($x % 2) print(" odd") ?>"><?php print $user['cognome']." ".$user['nome'] ?></td>
                <td class="admin_row<?php if($x % 2) print(" odd") ?>"><a href="#" onclick="document.forms[0].uid.value = <?php print $user['id_docente'] ?>; visualizza(event)" id="doc<?php print $user['id_docente'] ?>"><?php print $user['materia'] ?></a></td>
                <td class="admin_row _center<?php if($x % 2) print(" odd") ?>"><a href="#" id="rl<?php print $user['id_docente'] ?>" onclick="ruolo(<?php print $user['id_docente'] ?>)"><?php print $ruolo ?></a></td>
            </tr>
            <?php
                $x++;
            }
            include "../../shared/navigate.php";
            ?>
            <tr class="admin_row admin_menu">
                <td colspan="3" style="text-align: right">
                    <a href="<?php print $_SESSION['__config__']['html_root'] ?>admin/index.php">Torna menu</a>
                </td>
            </tr>
            <tr class="admin_row">
                <td colspan="3">&nbsp;&nbsp;&nbsp;
                	<input type="hidden" name="mat" />
        			<input type="hidden" name="uid" />
                </td>
            </tr>
        </table>
        </form>
       </div>
        <div id="footer">
			<p>Design: Luka Cvrk - <a href="http://www.solucija.com" title="Free Web Templates">Solucija</a></p>
		</div>
	</div>
</body>
</html>